<template>
  <div>
    <!-- <div>公共组件 -- {{ msg }}</div> -->
    <div>
      <button @click="login">模拟登录</button>
      <br />
      <button @click="question">题目列表</button>
      <br />
      <button @click="questionLog">答题日志</button>
      <br />
      <button @click="logout">退出登录</button>
    </div>
  </div>
</template>

<script>
import { reqlogin, reqgetQuestion, reqgetQuestionLog } from '@/apis/home.js'
import dayjs from 'dayjs'
export default {
  name: 'TestPage',
  props: {
    msg: String
  },
  data() {
    return {
      password: '',
      username: ''
    }
  },
  created() {
    console.log('HelloWorld组件被创建了')
    // this.init()
  },
  methods: {
    init() {
      const date = dayjs('2022-10-12').format('YYYY-MM-DD HH:mm:ss')
      console.log(date)
      //60 天后
      const date2 = dayjs().add(60, 'day').format('YYYY-MM-DD HH:mm:ss')
      console.log(date2)
      //60 天前
      const date3 = dayjs().subtract(60, 'day').format('YYYY-MM-DD HH:mm:ss')
      console.log(date3)
      const str = '20220921123412' // 2022-09-21 12:34:12
      // 判断 str 的30天后是否大于当前时间
      const isAfter = dayjs(str).add(30, 'day').isAfter(dayjs())
      console.log(isAfter)
      // 判断 str 的30天后是否小于当前时间
      const isBefore = dayjs(str).add(30, 'day').isBefore(dayjs())
      console.log(isBefore)
      // 判断 str 的60天后是否大于当前时间
      const isAfter2 = dayjs(str).add(60, 'day').isAfter(dayjs())
      console.log(isAfter2)

      // 判断 str 的60天后是否小于当前时间
      const isBefore2 = dayjs(str).add(60, 'day').isBefore(dayjs())
      console.log(isBefore2)
      // 判断 str 的60天后是否等于当前时间
      const isSame = dayjs(str).add(60, 'day').isSame(dayjs())
      console.log(isSame)
    },
    // 登录
    async login() {
      const res = await reqlogin({
        data: 'xnSa19sbN4yq52BWV%2BHaatAMqJi%2FNBe43R0kec4ke3Uj%2B3cmKiK3OYaRDKNuCusfkvmlCGM3Dn840CgQWiWqxyEwmU2BngWxOIjf7rYiB9WFNKyECrtoBpigI09TzniJuK4ORl7VG7gaDlcX3aJoaPytIP5XxwxRuFM2QL%2FWCnc%3D',
        loginTime: '1667182687256'
      })
      console.log(res, 11)
      console.log(11111)
      // // 把个人信息 user保存到本地
      // localStorage.setItem('user', JSON.stringify(res.data))
    },
    // 题目列表
    async question() {
      const res = await reqgetQuestion()
      console.log(res)
    },
    // 答题日志
    async questionLog() {
      const data = {
        question_id: 1,
        answer_index: 1,
        question_index: 1
      }
      const res = await reqgetQuestionLog(data)
      console.log(res)
    },
    // 退出登录
    logout() {
      localStorage.removeItem('user')
    }
  }
}
</script>

<style>
input,
button {
  margin: 12px;
}
</style>
